<template>
  <div class="container">
    <div>
      <el-row :gutter="12">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="分组">
              <el-select v-model="form.groupingValue" placeholder="请选择" @change="getLisencePlateList">
                <el-option
                  v-for="item in form.groupingList"
                  :key="item.index"
                  :label="item.CLIENT_NAME"
                  :value="item.CLIENT_NO"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="车牌号：">
              <el-select v-model="form.cph" placeholder="请选择" filterable clearable>
                <el-option
                  v-for="item in form.cphList"
                  :key="item.index"
                  :label="item.LICENSE_PLATE"
                  :value="item.VID"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="开始日期：">
              <!-- <el-date-picker
                v-model="form.StartDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker> -->
              <el-date-picker
                v-model="form.StartDate"
                type="datetime"
                placeholder="选择开始日期"
                value-format="yyyy-MM-dd HH:mm:ss"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="结束日期：">
              <!-- <el-date-picker
                v-model="form.EndDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker> -->
              <el-date-picker
                v-model="form.EndDate"
                type="datetime"
                placeholder="选择结束日期"
                value-format="yyyy-MM-dd HH:mm:ss"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form" style="float:left">
            <el-button size="mini" type="primary" @click="getlistdata">查 询</el-button>
            <el-button size="mini" type="success" @click="exportExcel">导 出</el-button>
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table v-loading="loading" :data="tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)" highlight-current-row>
      <el-table-column prop="车辆编号" label="车辆编号" align="center"  width="100"></el-table-column>
      <el-table-column prop="车辆名称" label="车辆名称" align="center"></el-table-column>
      <el-table-column prop="分组" label="车辆分组" align="center" width="170"></el-table-column>
      <el-table-column prop="车辆类型" label="车辆类型" align="center" width="170"></el-table-column>
      <el-table-column prop="状态" label="移动状态" align="center"></el-table-column>
      <!-- <el-table-column prop="RunTime" label="移动时间" align="center"></el-table-column> -->
      <el-table-column prop="最早移动时间" label="开始移动时间" align="center"></el-table-column>
      <el-table-column prop="最晚移动时间" label="最后移动时间" align="center"></el-table-column>
      <!-- <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-info" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'

import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {

    return {
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      form: {
        groupingList: [],
        groupingValue: '',
        cphList: [],//车牌号列表
        cph: '',//车牌号
        alermTypeList: [{ label: '1分钟', value: '1' }, { label: '5分钟', value: '5' }, { label: '10分钟', value: '10' }, { label: '30分钟', value: '30' }],
        alermTypeValue: '5',
        StartDate: formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd hh:mm:ss'),
        EndDate: formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss'),
      },
      originalData: [],
      tableData: [],
      loading: false,
      URLByTYPE: ''
    }
  },
  created () {
  },
  mounted () {
    if (localStorage.getItem('CurrentService') === '001') {
      this.URLByTYPE = 'Vehicle'
    }
    if (localStorage.getItem('CurrentService') === '003') {
      this.URLByTYPE = 'RubbishVehicle'
    }
    // this.getlistdata()
    this.getGroupingList()
  },
  methods: {
    //获取车辆分组列表
    async getGroupingList () {
      var url = this.URLByTYPE + '/GetGroupList?ClientNo=' + localStorage.getItem('CLIENT_NO') // zxdata
      let { data } = await this.$Http.get(url)
      this.form.groupingList = data
    },
    //获取车牌列表
    async getLisencePlateList () {
      this.form.cph = ''
      var url = this.URLByTYPE + '/GetVehicleCarListSelect?ClientNo=' + this.form.groupingValue
      const { data } = await this.$Http.get(url)
      this.form.cphList = data
      // this.form.cphList.unshift({ "LicensePlate": "全部" })
    },
    async getlistdata () {
      this.currentPage = 1;
      this.loading = true
      // var url = 'Vehicle/GetVehicleIsRun?CarNo=15375&StartDate=2021-06-01&EndDate=2021-06-23'
      var url = 'Vehicle/GetVehicleIsRun?StartDate=' + this.form.StartDate + '&EndDate=' + this.form.EndDate + '&CarNo=' + this.form.cph
      const { data } = await this.$Http.get(url)
      // 原始数据
      this.tableData = data
      // console.log(data)
      this.loading = false
    },
    // 导出Excel
    exportExcel () {
      let excelName = '移动状态信息表'
      const tHeader = ['车辆编号', '车辆名称', '车辆分组', '车辆类型', '移动状态', '开始移动时间', '最后移动时间']
      const filterVal = ['车辆编号', '车辆名称', '分组', '车辆类型', '状态', '最早移动时间', '最晚移动时间']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    //详情
    handleEdit (index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  width: 350px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
.el-form-item label {
  width: 80px;
}

</style>